<template>
  <el-form ref="queryFormRef" :inline="true" :model="queryModel">
    <template v-for="item in formSchema" :key="item.model">
      <FormItem :item="item" v-model="queryModel[item.model]" />
    </template>
    <!-- handle btn -->
    <el-form-item>
      <el-button type="primary" @click="submitForm">Create</el-button>
      <el-button @click="resetForm">Reset</el-button>
    </el-form-item>
  </el-form>
</template>

<script setup>
import { reactive, ref } from 'vue'
import FormItem from './FormItem.vue'

const props = defineProps(['formSchema', 'modelValue'])
const emit = defineEmits(['update:modelValue', 'handleQuery'])

const queryFormRef = ref(null)
const queryModel = reactive({
  ...props.modelValue
})

const submitForm = () => {
  emit('update:modelValue', { ...queryModel })
  emit('handleQuery', { ...queryModel })
}
const resetForm = () => {
  queryFormRef.value.resetFields()
}
</script>

<style lang="scss" scoped></style>
